-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bake(dev): plugins in dev server, with other fixes #15467
Conversation
@@ -2034,15 +2045,16 @@ pub fn IncrementalGraph(side: bake.Side) type { | |||
const dev = g.owner(); | |||
dev.graph_safety_lock.assertLocked(); | |||
|
|||
const abs_path = ctx.sources[index.get()].path.text; | |||
const path = ctx.sources[index.get()].path; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this copy intentional? Can it be a pointer instead? Path
is not a small struct
const path = ctx.sources[index.get()].path; | |
const path = &ctx.sources[index.get()].path; |
promise.setHandled(global.vm()); | ||
// TODO: remove this call, replace with a promise list that must | ||
// be resolved before the first bundle task can begin. | ||
global.bunVM().waitForPromise(promise); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sad
@@ -521,6 +583,10 @@ pub const Framework = struct { | |||
if (renderer == .server and framework.server_components != null) { | |||
try out.options.conditions.appendSlice(&.{"react-server"}); | |||
} | |||
if (mode == .development) { | |||
// Support `esm-env` package using this condition. | |||
try out.options.conditions.appendSlice(&.{"development"}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've never heard of this
@@ -76,7 +91,79 @@ if (side === "server") { | |||
} | |||
|
|||
function initImportMeta(m: HotModule): ImportMeta { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is client-side, for browsers I assume?
if (source_code_value.isEmptyOrUndefinedOrNull() or loader_as_int.isEmptyOrUndefinedOrNull()) { | ||
this.value = .{ .no_match = {} }; | ||
|
||
if (this.was_file) { | ||
// Faster path: skip the extra threadpool dispatch | ||
completion.bundler.graph.pool.pool.schedule(bun.ThreadPool.Batch.from(&this.parse_task.task)); | ||
this.bv2.graph.pool.pool.schedule(bun.ThreadPool.Batch.from(&this.parse_task.task)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bv2 implies the existence of bv3 and bv1
is there a better name?
@@ -1783,13 +1835,15 @@ pub const BundleV2 = struct { | |||
this.graph.heap.gc(true); | |||
} | |||
} | |||
var log = &load.completion.?.log; | |||
const log = this.bundler.log; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this changed? This will crash if the bundler thread writes to logger.Log
at the same time as the main thread. When using Bun.build
that can happen.
@@ -1846,7 +1922,7 @@ pub const BundleV2 = struct { | |||
this.graph.heap.gc(true); | |||
} | |||
} | |||
var log = &resolve.completion.?.log; | |||
const log = this.bundler.log; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. We shouldn't change this unless we're confident there's no thread-safety issue.
if (!record.source_index.isValid()) continue; | ||
if (loaders[record.source_index.get()] != .css) continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an extra pointer lookup, which slightly slows things down. Was the import_record.tag
inaccurate?
@@ -2595,7 +2666,7 @@ pub const BundleV2 = struct { | |||
import_record.path.pretty = rel; | |||
import_record.path = this.pathWithPrettyInitialized(path.*, target) catch bun.outOfMemory(); | |||
if (entry.kind == .css) { | |||
import_record.tag = .css; | |||
import_record.path.is_disabled = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave a comment explaining this?
temp, | ||
visits, | ||
o, | ||
record.source_index, | ||
record.tag == .css, | ||
loaders[record.source_index.get()] == .css, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can continue to use record.tag that's one less pointer lookup
|
||
// add a marker for the client runtime to tell that this is an ES module | ||
if (ast.exports_kind == .esm) { | ||
try stmts.inside_wrapper_prefix.append(Stmt.alloc(S.SExpr, .{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would ideally use the lazy export AST and then it can choose whichever output format is best.
@@ -334,12 +335,12 @@ export function runOnResolvePlugins(this: BundlerPlugin, specifier, inputNamespa | |||
} | |||
} | |||
|
|||
export function runOnLoadPlugins(this: BundlerPlugin, internalID, path, namespace, defaultLoaderId) { | |||
export function runOnLoadPlugins(this: BundlerPlugin, internalID, path, namespace, defaultLoaderId, isServerSide: boolean) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe isServerSide
could be an enum to clarify whether it means:
- RSC
- SSR
- !browser
// This is a re-export and the symbols created here are used to reference | ||
for (data.items) |*item| { | ||
const _name = p.loadNameFromRef(item.name.ref.?); | ||
const ref = try p.newSymbol(.other, _name); | ||
const ref = try p.newSymbol(.import, _name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooh i wonder what bugs this causes
column: i32, | ||
/// Number of bytes this location should highlight. | ||
/// 0 to just point at a single character | ||
length: usize = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this struct wasn't thoughtfully created, it was copypasta from esbuild
@@ -607,6 +607,9 @@ pub const ParseResult = union(enum) { | |||
.location = Logger.Location{ | |||
.file = path, | |||
.offset = this.loc.toUsize(), | |||
// TODO: populate correct line and column information | |||
.line = -1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to port the LineColumnTracker abstraction esbuild has
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments. Only blocking comment is the change to reference bundler.log
, as I worry it will cause crashes in Bun.build
.
I’m going to merge this to unblock further progress, but please take a look at the comments when you get a chance. |
Co-authored-by: paperdave <[email protected]> Co-authored-by: Jarred Sumner <[email protected]>
resolveDir
to onResolve pluginsexport { x } from 'y';
export { x as y }
The requested module '${id}' does not provide an export named '${key}'
import.meta.hot
, implementimport.meta.hot.dispose
example project: https://github.com/paperdave/bake-svelte-plugin-example